package grails.goods.base

import grails.gorm.transactions.Transactional

@Transactional
class BaseService {

    def sessionFactory

    /**
     * 计算分页 起始页
     * @param pageNum
     * @param max
     * @return
     */
    static getStartNum(def pageNum, def max) {
        return (pageNum - 1) * max
    }

    /**
     * 计算总页数
     * @param pageSize 每页显示数量
     * @param totalCount 总数据量
     * @return
     */
//    static getTotalPage(def pageSize, def totalCount) {
//        return totalCount % pageSize == 0 ? totalCount / pageSize : (totalCount / pageSize) + 1
//    }
    static getTotalPage(def everyPage, def totalCount) {
        int totalPage = 0
        if (totalCount % everyPage == 0) {
            totalPage = totalCount / everyPage
        } else {
            totalPage = totalCount / everyPage + 1
        }
        return totalPage
    }
}
